package com.lfg.leetcode.leetcode200;

public class No220containsNearbyAlmostDuplicate {

    public static void main(String[] args) {
        boolean ret = containsNearbyAlmostDuplicate(new int[]{-1, 2147483647}, 1, 2147483647);
        System.out.println(ret);
    }

    public static boolean containsNearbyAlmostDuplicate(int[] nums, int k, int t) {
        for (int i = 0; i < nums.length; i++) {

        }

        return false;
    }

    public static boolean containsNearbyAlmostDuplicate2(int[] nums, int k, int t) {
        if (k <= 0) {
            return false;
        }
        for (int i = 0; i < nums.length; i++) {
            for (int j = 1; j <= k && j < nums.length; j++) {
                int end = i + j;
                if (end >= nums.length) {
                    break;
                }
                if (Math.abs((long) (nums[i] - nums[end])) <= t) {
                    return true;
                }
            }
        }
        return false;
    }


    public static boolean containsNearbyAlmostDuplicate3(int[] nums, int k, int t) {
        if (k <= 0) {
            return false;
        }

        int len = nums.length;
        int end = 1;
        int start = 0;
        while (start < len - 1) {
            if (start != end && Math.abs((long) nums[start] - nums[end]) <= t) {
                return true;
            }
            if (end - start == k || len - 1 == end) {
                start++;
                if (t != 0) {
                    end = start + 1;
                }
            } else {
                end++;
            }
        }
        return false;
    }
}
